﻿using System;
using System.Collections.Generic;
using System.Text;

using Obsidian.Utils;
using Obsidian.Edm;
using Obsidian.Data.Sql;
using Oak.Model;

namespace Oak.MagSys.Data
{
    public class MenuItemDA
    {

        internal List<MsMenuItemInfo> SelectList(MsMenuItemQry qry)
        {
            MsMenuItemInfo mi = new MsMenuItemInfo();
            IDbHandler dbh = mi.CreateHandler();
            dbh.SetFields(mi.Fields);
            if (!qry.MenuItemIds.IsNull)
            {
                long[] itemIds = qry.MenuItemIds.SplitLong(',');
                if (itemIds.Length > 0)
                    dbh.Where(mi.ItemId.In(itemIds));
            }
            dbh.OrderBy(mi.Depth);
            dbh.OrderBy(mi.SortOrder);
            DataReader dr = dbh.Select();
            return dr.ReadList<MsMenuItemInfo>();
        }

    }
}
